package ZuoYe03_YouCanFangFa2_0507;

import java.util.Scanner;

/**
 * 2：公司company有公司名称，注册地址address，电话phone，经营范围business等属性，
 * 公司有很多员工employee（暂用String数组表示），公司有招聘offer/Recruitment员工方法，
 * 有输出员工信息information方法，以及辞退fire、dismiss员工方法(*选做)。用oo的思想模拟
 * 
 * @author zhaoyang
 *
 */
public class Company {
	String companyName;
	String companyAddress;
	String companyPhone;
	String companyBusiness;
	String employeeName;
	String[] employee = new String[10];

	public boolean findEmployee(String employeeName) {// 寻找员工
		for (int i = 0; i < employee.length; i++) {
			if (employeeName.equals(employee[i])) {
				return true;
			}
		}
		return false;
	}

	public void offer(String employeeName) {// 招聘员工
		System.out.println("招聘员工");
		if (findEmployee(employeeName)) {
			System.out.println("员工姓名不能重复!");
			return;
		}
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] == null) {
				employee[i] = employeeName;
				System.out.println("添加成功!");
				return;
			}
		}
		System.out.println("添加失败!");

	}

	public void showInfor() {// 显示员工信息
		System.out.println("员工信息：");
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] != null) {
				System.out.println(employee[i]);
			}
		}
	}

	public int findEmployeeNum(String name) {// 寻找员工编号
		int i, num = 0;
		for (i = 0; i < employee.length; i++) {
			if (name.equals(employee[i])) {
				num = i;
			}
		}
		return num;
	}

	public void fire(String name) {// 开除员工
		employee[findEmployeeNum(name)] = null;
		System.out.println("已辞退员工" + name);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Company a = new Company();
		Scanner input = new Scanner(System.in);
		while (true) {
			System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>");
			System.out.println("招聘员工请按1，\n展示员工信息请按2，\n开除员工请按3，\n退出程序请按0：");
			int flag = input.nextInt();
			if (flag == 1) {
				System.out.println("请输入招入新员工的姓名：");
				a.employeeName = input.next();
				a.offer(a.employeeName);
			} else if (flag == 2) {
				a.showInfor();
			} else if (flag == 3) {
				System.out.println("请输入要开除的老员工的姓名：");
				a.employeeName = input.next();
				a.fire(a.employeeName);
			} else if (flag == 0) {
				System.out.println("程序退出,谢谢使用！");
				break;
			}
		}
	}

}
